import java.util.Objects;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2024-06-03
 * Time: 20:08
 */
public class Student implements Comparable<Student>{
    //表中有几列，这里就有几个属性
    private String department;
    private String grade;
    private String name;
    private int age;
    private String hometown;

    public Student(String department, String grade, String name, int age, String hometown) {
        this.department = department;
        this.grade = grade;
        this.name = name;
        this.age = age;
        this.hometown = hometown;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return age == student.age && Objects.equals(department, student.department) && Objects.equals(grade, student.grade) && Objects.equals(name, student.name) && Objects.equals(hometown, student.hometown);
    }

    @Override
    public int hashCode() {
        return Objects.hash(department, grade, name, age, hometown);
    }

    public Student() {
    }
    public String getDepartment() {
        return department;
    }

    public void setDepartment(String department) {
        this.department = department;
    }

    public String getGrade() {
        return grade;
    }

    public void setGrade(String grade) {
        this.grade = grade;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getHometown() {
        return hometown;
    }

    public void setHometown(String hometown) {
        this.hometown = hometown;
    }

    @Override
    public String toString() {
        return "Student{" +
                "department='" + department + '\'' +
                ", grade='" + grade + '\'' +
                ", name='" + name + '\'' +
                ", age=" + age +
                ", hometown='" + hometown + '\'' +
                '}';
    }

    @Override
    public int compareTo(Student o) {
        //先按年龄升序排序，如果年龄一样，再按姓名排序
        if (this.age > o.age){
            return 1;//如果我的年龄比你大，返回正数，升序
        }else if(this.age<o.age){
            return  -1;
        }else {
            return this.name.compareTo(o.name);
        }
    }
}
